package com.haiyou.data.game.role;

import java.util.function.Consumer;

import org.springframework.util.StringUtils;

import com.haiyou.common.constants.ErrCode;
import com.haiyou.common.entity.Prefix;
import com.haiyou.common.util.check.Assert;
import com.haiyou.data.common.accessor.annotation.CachedPolicy;
import com.haiyou.data.common.accessor.annotation.ExpiryPolicy;
import com.haiyou.data.common.accessor.redis.redisson.bucket.BucketAccessor;
import com.haiyou.data.common.cache.redis.RKeys;
import com.haiyou.data.common.cache.redis.key.RedisPrefix;

@CachedPolicy(expiryPolicy = @ExpiryPolicy(timeToLive = -1))
@Prefix(RedisPrefix.player_role)
public class PlayerRoleTableAccessor extends BucketAccessor<PlayerRoleTable> {

	/**
	 * 通过uid  查询玩家角色信息
	 * 
	 * @param uid
	 * @return
	 */
	public PlayerRoleTable getByUid(String uid) {
		Assert.isTrue(StringUtils.hasLength(uid), ErrCode.ERROR_PARAMETER, "uid not null");
		String key = RKeys.createRId(getKeyPrefix(),uid);
		return get(key);
	}

	public String generateKey(String uid) {
		return  RKeys.createRId(getKeyPrefix(),uid);
	}
	
	@Override
	public String generateKey() {
		Assert.isTrue(false, ErrCode.METHOD_NOT_SUPPORT);
		return null;
	}

	@Override
	public PlayerRoleTable generate(Consumer<PlayerRoleTable> consumer) {
		Assert.isTrue(false, ErrCode.METHOD_NOT_SUPPORT);
		return null;
	}
}
